﻿define(function (require) {

    function handleATag(aTagItem, model) {
        var $aTagItem = $(aTagItem);
        var url = $aTagItem.attr('href');
        $aTagItem.attr('href', '#').unbind();

        $aTagItem.click(function (event) {
            $.postMessage('url:' + url, '*', parent);
            event.preventDefault();
            event.stopPropagation();
        });
    };

    return Backbone.View.extend({
        //... is a list tag.
        tagName: "li",
        template: _.template($("#li_notification").html()),
        events: {
            "click .feed-close": "clear",
            "mouseover": "showClose",
            "mouseout": "hideClose"
        },
        initialize: function () {
            var $self = this;
            $(this.el).attr('data-theme', 'd')
                      .addClass('ui-btn ui-btn-icon-right ui-li ui-btn-up-d  noti')

            _.bindAll(this, 'render');
            this.model.bind('change', this.render);
            this.model.view = this;
        },
        showClose: function () {
            $(this.el).find('.feed-close').show();
        },
        hideClose: function () {
            $(this.el).find('.feed-close').hide();
        },
        render: function () {
            $(this.el).html(this.template(this.model.toJSON()));

            var element = $(this.el)[0];
            $(element).find('.feed-close').data('cid', this.model.cid);

            $(this.el).find('a.ezlink').each(function (index, item) {
                handleATag(item, this.model);
            });

            return this;
        },
        remove: function () {
            $(this.el).remove();
        },

        // Remove the item, destroy the model.
        clear: function () {
            //edit feed status
            this.model.setIsAvailable();
        }
    });
});